﻿@using Apps.Web.Core;
@using Apps.Web;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "LMS_TEMPLATE";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div id="uploadExcel" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false">
    <form name="form1" method="post" id="form1">
        <table>
            <tr>
                <th style="padding:20px; "> Excel：</th>
                <td style="padding:20px; ">
                    <input name="ExcelPath" type="text" maxlength="255" id="txtExcelPath" readonly="readonly" style="width:200px" class="txtInput normal left">
                    <a href="javascript:$('#FileUpload').trigger('click').void(0);" class="files">@Resource.Browse</a>
                    <input class="displaynone" type="file" id="FileUpload" name="FileUpload" onchange="Upload('ExcelFile', 'txtExcelPath', 'FileUpload'); ">
                    <span class="uploading">@Resource.Uploading</span>
                </td>
            </tr>
        </table>
        <div class="endbtndiv">
            <a id="btnSave" href="javascript:ImportData()" class="easyui-linkbutton btns">直接保存</a>
            <a id="btnReturn" href="javascript:$('#uploadExcel').window('close')" class="easyui-linkbutton btnc">@Resource.Cancel</a>
        </div>
    </form>
</div>
<table style="width:100%">
    <tbody>
        <tr>
            <td style="width:98%;vertical-align: top">
                <div class="mvctool">
                    <input id="txtQueryParent" style="width:300px" class="searchText" />
                    @Html.ToolButton("btnQueryParent", "fa fa-search", Resource.Query, ref perm, "Query", true)
                    @Html.ToolButton("btnCreateParent", "fa fa-plus", Resource.Create, ref perm, "Create", true)
                    @Html.ToolButton("btnEditParent", "fa fa-pencil", Resource.Edit, ref perm, "Edit", true)
                    @Html.ToolButton("btnCopyParent", "fa fa-pencil", "复制", ref perm, "Copy", true)
                    @Html.ToolButton("btnDeleteParent", "fa fa-trash", Resource.Delete, ref perm, "Delete", true)
                </div>
                <table id="ListParent"></table>
            </td>
        </tr>
        <tr style="width:3px;"><td>复检模板详情</td></tr>
        <tr>
            <td style="vertical-align: top">
                <table id="List"></table>
            </td>
        </tr>
    </tbody>
</table>

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<script type="text/javascript">
    $(function () {
        $('#ListParent').datagrid({
            url: '@Url.Action("GetListParent")',
            width: SetGridWidthSub(10),
            methord: 'post',
            height: SetGridHeightSub(360),
            fitColumns: true,
            sortName: 'UPDATE_TIME',
            sortOrder: 'desc',
            idField: 'TEMPLATE_ID',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            rownumbers: true,//行号
            onClickRow: clickRow,
            onLoadSuccess: function (data) {
                var allRows = $('#ListParent').datagrid('getRows');
                if (allRows.length > 0) {
                    //$('#ListParent').datagrid('selectRow', 0);
                    clickRow(0, allRows[0]);
                }
            },
            columns: [[
                { field: 'TEMPLATE_NAME', title: '模版名称', width: 80, sortable: true },
                { field: 'TEMPLATE_TYPE', title: '模版类型', width: 80, sortable: true, formatter: function (val) { return val == '0' ? "入厂煤种化验模板" : ((val == '1') ? "入厂物料化验模板" : "其他"); } },
                { field: 'TEMPLATE_DESC', title: '模版描述', width: 80, sortable: true },
                { field: 'UPDATE_USERS', title: '更新人', width: 80,sortable:true },
                { field: 'UPDATE_TIME', title: '更新时间', width: 80,sortable:true }
            ]]
        }).datagrid('getPager').pagination({ showPageList: true, showRefresh: true });
         $(window).resize(function() {
             resizeLayout();
         });
        $('#List').datagrid({
            url: '@Url.Action("GetListDetail")',
            width: SetGridWidthSub(10),
            methord: 'post',
            height: 300,
            fitColumns: true,
            sortName: 'INDEX_ID',
            sortOrder: 'desc',
            idField: 'INDEX_ID',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: false,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            //rownumbers: true,//行号
            onLoadSuccess: function(data) {                @foreach(var r in perm){ if (r.Category == 2) { @Html.Raw("$(this).datagrid('hideColumn','" + r.KeyCode + "'); "); } }
            },
            columns: [[
                { field: 'INDEX_NAME', title: '化验项目', width: 80, sortable: true },
                { field: 'INDEX_DISNAME', title: '简码', width: 50, sortable: true },
                { field: 'VALUE_TYPE', title: '值类型', width: 80, sortable: true, formatter: function (val) { return val == '0' ? "" : ((val == '1') ? "区间值校验" : "基值波动范围"); } },
                { field: 'VALUE_SHOW', title: '显示', width: 80, sortable: true, formatter: function (val) { return val == '0' ? "否" : ((val == '1') ? "是" : ""); } },
                { field: 'VALUE_TEST', title: '化验', width: 80, sortable: true, formatter: function (val) { return val == '0' ? "否" : ((val == '1') ? "是" : ""); } },
                { field: 'VALUE_CHECK', title: '复检', width: 80, sortable: true, formatter: function (val) { return val == '0' ? "否" : ((val == '1') ? "是" : ""); } },
                { field: 'VALUE_BASE', title: '基值', width: 60, sortable: true },
                { field: 'VALUE_MIN', title: '最小值', width: 80, sortable: true, formatter: valiData },
                { field: 'VALUE_MAX', title: '最大值', width: 80, sortable: true, formatter: valiData },
                { field: 'TEMPLATE_ID', title: '化验模版编号', hidden: true, width: 80, sortable: true },
                { field: 'INDEX_ID', title: '化验指标编号', hidden: true,width: 80,hidden:true }
            ]]
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
        {
            $("#List,#ListParent").datagrid('load');
        }
        else
        {
            $("#List,#ListParent").datagrid('reload');
        }
    }
    function frameReturnByMes(mes) {
        $.messageBox5s(Lang.Tip, mes);
    }
    $(function () {
        $("#btnCreateParent").click(function () {
            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='auto' frameborder='0'' src='@Url.Action("CreateParent")'></iframe>");
            $("#modalwindow").window({ title: Lang.Create, width: 800, height: 730, iconCls: 'fa fa-plus' }).window('open');
        });
        $("#btnEditParent").click(function () {
            var row = $('#ListParent').datagrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='99%'  frameborder='0' src='@Url.Action("EditParent")?id=" + row.TEMPLATE_ID + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Edit', width: 800, height: 730, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
        });
        $("#btnQueryParent").click(function () {
            var queryStr = $("#txtQueryParent").val();
            if (queryStr == null) {
                queryStr = "%";
            }
            $("#ListParent").datagrid("load", { queryStr: queryStr });

        });
        $("#btnDeleteParent").click(function () {
            var row = $('#ListParent').datagrid('getSelected');
            if (row != null) {
                $.messager.confirm(index_lang_tip, '@Resource.YouWantToDeleteTheSelectedRecords', function (r) {
	                    if (r) {
                            $.post("@Url.Action("DeleteParent")?id=" + row.TEMPLATE_ID, function (data) {
	                            if (data.type == 1)
	                                $("#ListParent").datagrid('load');
	                            $.messageBox5s(Lang.Tip, data.message);
	                        }, "json");

	                    }
	                });
	            } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
	        });
    });
    function ImportData()
    {
        showLoading();
        var url = "@Url.Action("Import")?filePath="+$("#txtExcelPath").val();
        $.post(url, function(data) {
            if (data.type == 1)
            {
             $("#List").datagrid('load');
             $('#uploadExcel').window('close');
             $('#FileUpload').val('');
            }
            hideLoading();
            $.messageBox5s('提示', data.message);
        }, "json");
    }
    function resizeLayout()
     {
         setTimeout(function () {
             $('#ListParent').datagrid('resize', {
             }).datagrid('resize', {
                 height: SetGridHeightSub(45)
             });
             $('#List').datagrid('resize', {
             }).datagrid('resize', {
                 width: $(window).width() - 450,
                 height: SetGridHeightSub(45)
             });
         },100);
    }

    function clickRow(idx, row) {
        if (row != null) {
            $('#List').datagrid("load", { parentId: row.TEMPLATE_ID });
        }
    }

    function valiData(val) {
        if (val == null) {
            return "";
        }
        return val;
    }
</script>

